<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
		<link rel="stylesheet" type="text/css" href="../static/dist/css/bootstrap.css" />
	</head>
	<style type="text/css">
		#body {
			width: 100%;
			height: 100vh;
			display: flex;
			align-items: center;
			/* justify-content: center; */
			flex-direction: column;
			position: relative;
		}

		.icon img {
			margin-top: 100px;
			height: 80px;
		}

		.text {
			font-size: 34px;
			color: #3399FF;
			margin: 50px 0 20px;
		}
		.text2 {
			text-align: center;
			margin: 0 60px;
		}

		.button {
			position: absolute;
			bottom: 50px;
		}

		.button a {
			background-color: #FFFFFF;
			color: #3399FF;
			padding: 3px 15px;
			margin: 0 20px;
		}
	</style>
	<body>
		<div id="body">
			<div class="icon">
				<img src="">
			</div>
			<div class="text">
				···
			</div>
			<div class="text2" style="opacity: 0.5;">
			</div>
			<div class="button">
				<a type="button" onclick="unband()" class="btn btn-default" style="color: #999999;" href="#">
					解除绑定
				</a>
				<a class="btn btn-primary" href="wxIndex.html">进入列表页</a>
			</div>
		</div>
	</body>
	<script src="../static/js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
	<script>
		function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return decodeURI(r[2]);
			return null;
		}
		var flag = getUrlParam("flag")
		if (flag == "Y") {
			$(".text").text("已绑定，登录成功")
			$("img").attr("src","../static/img/icon2.png")
			// setTimeout(function() {
			// 	window.location.href = "wxIndex.html"
			// }, 5000)
		}else if(flag == "S"){
			$(".text").text("绑定成功")
			$("img").attr("src","../static/img/icon2.png")
			// setTimeout(function() {
			// 	window.location.href = "wxIndex.html"
			// }, 5000)
		}else if(flag == "N"){
			$(".text").text("绑定失败").css("color","red")
			$(".text2").text("如果原本就绑定了请直接进入列表页，如果你需要改绑请点击解绑即可重新绑定。").css("color","#666")
			$("img").attr("src","../static/img/error.png")
		}else{
			$(".text").text("绑定失败").css("color","red")
			$(".text2").text("不明原因导致绑定失败，请在官方微信公众号上点击绑定按钮进行重新绑定。").css("color","#666")
			$("img").attr("src","../static/img/error.png")
		}

		function unband() {
			$(".text").text("···")
			$.ajax({
				type: 'GET',
				url: "../wechat/unband",
				data: {},
				success: function(resp) {
					if (typeof("sdsd") == typeof(resp) && resp.length <100) {
						var resp = eval('(' + resp + ')')
					}
					if (resp.code == 100) {
						$(".text").text("解绑成功")
						setTimeout(function() {
							window.location.href =
								"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5acca64b07361a8c&redirect_uri=http%3A%2F%2Ftest.aimendian.cn%2Fface%2Fgrant&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
						}, 800);
					} else if(resp.code == 302){
						$(".text").text("未登录")
						setTimeout(function() {
							window.location.href =
								"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5acca64b07361a8c&redirect_uri=http%3A%2F%2Ftest.aimendian.cn%2Fface%2Fgrant&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
						}, 800);
					}else{
						console.log(resp)
					}
				},
				error: function(error) {
					console.log(error)
				}
			})
		}
	</script>
</html>
